home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / print / gsview10.zip / dialog.c < prev    next >
C/C++ Source or Header  |  1993-07-06  |  19KB  |  638 lines

  1. /*
  2.  * dialog.c -- General dialog boxes for GSVIEW.EXE, 
  3.  *              a graphical interface for MS-Windows Ghostscript
  4.  * Copyright (C) 1993  Russell Lang
  5.  *
  6.  * This program is free software; you can redistribute it and/or modify
  7.  * it under the terms of the GNU General Public License as published by
  8.  * the Free Software Foundation; either version 2 of the License, or
  9.  * (at your option) any later version.
  10.  *
  11.  * This program is distributed in the hope that it will be useful,
  12.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14.  * GNU General Public License for more details.
  15.  *
  16.  * You should have received a copy of the GNU General Public License
  17.  * along with this program; if not, write to the Free Software
  18.  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  19.  *
  20.  *   Author: Russell Lang
  21.  * Internet: rjl@monu1.cc.monash.edu.au
  22.  */
  23.  
  24. #define STRICT
  25. #include <windows.h>
  26. #include <windowsx.h>
  27. #include <commdlg.h>
  28. #include <shellapi.h>
  29. #include <mmsystem.h>
  30. #include <stdio.h>
  31. #include <stdlib.h>
  32. #include <string.h>
  33. #include <ctype.h>
  34. #include <dir.h>
  35. #include <io.h>
  36. #define NeedFunctionPrototypes 1
  37. #include "ps.h"
  38. #include "gsview.h"
  39.  
  40.  
  41. BOOL
  42. getfilename(LPSTR filename, BOOL save, UINT filter, UINT title, UINT help)
  43. {
  44. LPSTR old_lpstrFile;
  45. LPCSTR old_lpstrTitle;
  46. char szTitle[MAXSTR];
  47. BOOL flag;
  48.     if (help)
  49.         LoadString(phInstance, help, szHelpTopic, sizeof(szHelpTopic));
  50.     old_lpstrTitle = ofn.lpstrTitle;
  51.     if (title) {
  52.         LoadString(phInstance, title, szTitle, sizeof(szTitle));
  53.         ofn.lpstrTitle = (LPCSTR)szTitle;
  54.     }
  55.     old_lpstrFile = ofn.lpstrFile;
  56.     if (filename != (LPSTR)NULL)
  57.         ofn.lpstrFile = filename;
  58.     ofn.nFilterIndex = filter;
  59.     if (save)
  60.         flag = GetSaveFileName(&ofn);
  61.     else
  62.         flag = GetOpenFileName(&ofn);
  63.     ofn.lpstrTitle = old_lpstrTitle;
  64.     ofn.lpstrFile = old_lpstrFile;
  65.     ofn.nFilterIndex = FILTER_PS;
  66.     if ( save && flag && 
  67.             (dfname[0]!='\0') && (lstrcmp(filename, dfname) == 0) ) {
  68.         gserror(IDS_NOTDFNAME, NULL, MB_ICONEXCLAMATION, SOUND_ERROR);
  69.         flag = FALSE;
  70.     }
  71.     return flag;
  72. }
  73.  
  74. /* Input Dialog Box structures */
  75. LPSTR input_prop = "input_prop";
  76. struct input_param {
  77.     LPSTR prompt;
  78.     LPSTR answer;
  79. };
  80.  
  81. BOOL
  82. get_string(char *prompt, char *answer)
  83. {
  84. struct input_param param;
  85. DLGPROC lpProcInput;
  86. BOOL flag;
  87.     param.answer = answer;
  88.     param.prompt = prompt;
  89.     lpProcInput = (DLGPROC)MakeProcInstance((FARPROC)InputDlgProc, phInstance);
  90.     flag = DialogBoxParam( phInstance, "InputDlgBox", hwndimg, lpProcInput, (LPARAM)¶m);
  91.     FreeProcInstance((FARPROC)lpProcInput);
  92.     return flag;
  93. }
  94.  
  95.  
  96. /* input string dialog box */
  97. BOOL CALLBACK _export
  98. InputDlgProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
  99. {
  100.     switch(message) {
  101.         case WM_INITDIALOG:
  102.         {
  103.           HLOCAL hlocal;
  104.           LPSTR *panswer;
  105.           struct input_param *pparam = (struct input_param *)lParam;
  106.           SetDlgItemText(hDlg, ID_PROMPT, pparam->prompt);
  107.           SetDlgItemText(hDlg, ID_ANSWER, pparam->answer);
  108.           /* save address of answer string in property list */
  109.           hlocal = LocalAlloc(LHND, sizeof(pparam->answer));
  110.           panswer = (LPSTR *)LocalLock(hlocal);
  111.           if (panswer != (LPSTR *)NULL) {
  112.             *panswer = pparam->answer;
  113.         LocalUnlock(hlocal);
  114.             SetProp(hDlg, input_prop, (HANDLE)hlocal);
  115.           }
  116.         }
  117.             return( TRUE);
  118.         case WM_COMMAND:
  119.             switch(LOWORD(wParam)) {
  120.         case ID_HELP:
  121.             SendMessage(hwndimg, help_message, 0, 0L);
  122.             return(FALSE);
  123.                 case ID_ANSWER:
  124.                     return(TRUE);
  125.         case IDOK:
  126.             {
  127.               HLOCAL hlocal = (HLOCAL)GetProp(hDlg, input_prop); 
  128.               LPSTR *panswer;
  129.                   panswer = (LPSTR *)LocalLock(hlocal);
  130.                   if (panswer != (LPSTR *)NULL) {
  131.                 GetDlgItemText(hDlg, ID_ANSWER, *panswer, MAXSTR);
  132.             LocalUnlock(hlocal);
  133.               }
  134.               LocalFree(hlocal);
  135.               RemoveProp(hDlg, input_prop);
  136.             }
  137.                     EndDialog(hDlg, TRUE);
  138.                     return(TRUE);
  139.                 case IDCANCEL:
  140.             {
  141.               HLOCAL hlocal = (HLOCAL)GetProp(hDlg, input_prop); 
  142.               LocalFree(hlocal);
  143.               RemoveProp(hDlg, input_prop);
  144.             }
  145.                     EndDialog(hDlg, FALSE);
  146.                     return(TRUE);
  147.                 default:
  148.                     return(FALSE);
  149.             }
  150.         default:
  151.             return(FALSE);
  152.     }
  153. }
  154.  
  155.  
  156. /* copyright dialog box */
  157. BOOL CALLBACK _export
  158. AboutDlgProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
  159. {
  160.     switch(message) {
  161.         case WM_INITDIALOG:
  162.             SetDlgItemText(hDlg, ABOUT_VERSION, GSVIEW_VERSION);
  163.             return( TRUE);
  164.     case WM_LBUTTONDBLCLK:
  165.         {DWORD dwUnit = GetDialogBaseUnits();
  166.         RECT rect; POINT pt;
  167.         pt.x = LOWORD(lParam); pt.y = HIWORD(lParam);
  168.         rect.left   =   8 * LOWORD(dwUnit) / 4;
  169.         rect.top    = 138 * HIWORD(dwUnit) / 8;
  170.         rect.right  = 240 * LOWORD(dwUnit) / 4 + rect.left;
  171.         rect.bottom =   8 * HIWORD(dwUnit) / 8 + rect.top;
  172.         if (PtInRect(&rect,pt)) {
  173.         BITMAP bm;
  174.         HBITMAP hbitmap_old;
  175.         HBITMAP hbitmap = LoadBitmap(phInstance,"gsview_bitmap");
  176.         HDC hdc = GetDC(hDlg);
  177.         HDC hdcsrc = CreateCompatibleDC(hdc);
  178.         hbitmap_old = SelectObject(hdcsrc,hbitmap);
  179.         GetObject(hbitmap, sizeof(BITMAP),&bm);
  180.         BitBlt(hdc, rect.right-bm.bmWidth,rect.bottom-bm.bmHeight,
  181.            bm.bmWidth,bm.bmHeight,hdcsrc,0,0,SRCCOPY);
  182.         SelectObject(hdcsrc,hbitmap_old);
  183.         DeleteObject(hbitmap);
  184.         DeleteDC(hdcsrc);
  185.         ReleaseDC(hDlg,hdc);
  186.         }
  187.         }
  188.         return FALSE;
  189.         case WM_COMMAND:
  190.             switch(LOWORD(wParam)) {
  191.                 case IDOK:
  192.                     EndDialog(hDlg, TRUE);
  193.                     return(TRUE);
  194.                 default:
  195.                     return(FALSE);
  196.             }
  197.         default:
  198.             return(FALSE);
  199.     }
  200. }
  201.  
  202. /* information about document dialog box */
  203. BOOL CALLBACK _export
  204. InfoDlgProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
  205. {
  206.     switch(message) {
  207.         case WM_INITDIALOG:
  208.       { char buf[MAXSTR];
  209.         int n;
  210.         if (dfname[0] != '\0') {
  211.                 SetDlgItemText(hDlg, INFO_FILE, dfname);
  212.         if (doc) {
  213.             if (is_ctrld)
  214.             LoadString(phInstance, IDS_NOTDSC, buf, sizeof(buf));
  215.             else  {
  216.             if (doc->epsf) {
  217.                 switch (preview) {
  218.                 case IDS_EPSI:
  219.                   LoadString(phInstance, IDS_EPSI, buf, sizeof(buf));
  220.                   break;
  221.                 case IDS_EPST:
  222.                   LoadString(phInstance, IDS_EPST, buf, sizeof(buf));
  223.                   break;
  224.                 case IDS_EPSW:
  225.                   LoadString(phInstance, IDS_EPSW, buf, sizeof(buf));
  226.                   break;
  227.                 default:
  228.                   LoadString(phInstance, IDS_EPSF, buf, sizeof(buf));
  229.                 }
  230.             }
  231.             else
  232.                 LoadString(phInstance, IDS_DSC, buf, sizeof(buf));
  233.             }
  234.                     SetDlgItemText(hDlg, INFO_TYPE, buf);
  235.             SetDlgItemText(hDlg, INFO_TITLE, doc->title ? doc->title : "");
  236.             SetDlgItemText(hDlg, INFO_DATE, doc->date ? doc->date : "");
  237.             sprintf(buf, "%d %d %d %d", doc->boundingbox[LLX], doc->boundingbox[LLY], 
  238.             doc->boundingbox[URX], doc->boundingbox[URY]);
  239.             SetDlgItemText(hDlg, INFO_BBOX, buf);
  240.             switch(doc->orientation) {
  241.             case LANDSCAPE:
  242.                     LoadString(phInstance, IDS_LANDSCAPE, buf, sizeof(buf));
  243.                 break;
  244.             case PORTRAIT:
  245.                     LoadString(phInstance, IDS_PORTRAIT, buf, sizeof(buf));
  246.                 break;
  247.             default:
  248.                 buf[0] = '\0';
  249.             }
  250.             SetDlgItemText(hDlg, INFO_ORIENT, buf);
  251.             switch(doc->pageorder) {
  252.             case ASCEND: 
  253.                     LoadString(phInstance, IDS_ASCEND, buf, sizeof(buf));
  254.                 break;
  255.             case DESCEND: 
  256.                     LoadString(phInstance, IDS_DESCEND, buf, sizeof(buf));
  257.                 break;
  258.             case SPECIAL:
  259.                     LoadString(phInstance, IDS_SPECIAL, buf, sizeof(buf));
  260.                 break;
  261.             default:
  262.                 buf[0] = '\0';
  263.             }
  264.             SetDlgItemText(hDlg, INFO_ORDER, buf);
  265.             if (doc->default_page_media && doc->default_page_media->name) {
  266.                 sprintf(buf,"%s %d %d",doc->default_page_media->n